home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / utils / elp.el.z / elp.el
Encoding:
Text File  |  1998-05-21  |  22.1 KB  |  609 lines

  1. ;;; elp.el --- Emacs Lisp Profiler
  2.  
  3. ;; Copyright (C) 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author:        1994-1996 Barry A. Warsaw
  6. ;; Maintainer:    tools-help@python.org
  7. ;; Created:       26-Feb-1994
  8. ;; Version:       2.37
  9. ;; Last Modified: 1996/10/23 04:06:58
  10. ;; Keywords:      debugging lisp tools
  11.  
  12. ;; This file is part of GNU Emacs.
  13.  
  14. ;; GNU Emacs is free software; you can redistribute it and/or modify
  15. ;; it under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation; either version 2, or (at your option)
  17. ;; any later version.
  18.  
  19. ;; GNU Emacs is distributed in the hope that it will be useful,
  20. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. ;; GNU General Public License for more details.
  23.  
  24. ;; You should have received a copy of the GNU General Public License
  25. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  26. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  
  28. ;;; Commentary:
  29. ;;
  30. ;; If you want to profile a bunch of functions, set elp-function-list
  31. ;; to the list of symbols, then do a M-x elp-instrument-list.  This
  32. ;; hacks those functions so that profiling information is recorded
  33. ;; whenever they are called.  To print out the current results, use
  34. ;; M-x elp-results.  If you want output to go to standard-output
  35. ;; instead of a separate buffer, setq elp-use-standard-output to
  36. ;; non-nil.  With elp-reset-after-results set to non-nil, profiling
  37. ;; information will be reset whenever the results are displayed.  You
  38. ;; can also reset all profiling info at any time with M-x
  39. ;; elp-reset-all.
  40. ;;
  41. ;; You can also instrument all functions in a package, provided that
  42. ;; the package follows the GNU coding standard of a common textual
  43. ;; prefix.  Use M-x elp-instrument-package for this.
  44. ;;
  45. ;; If you want to sort the results, set elp-sort-by-function to some
  46. ;; predicate function.  The three most obvious choices are predefined:
  47. ;; elp-sort-by-call-count, elp-sort-by-average-time, and
  48. ;; elp-sort-by-total-time.  Also, you can prune from the output, all
  49. ;; functions that have been called fewer than a given number of times
  50. ;; by setting elp-report-limit.
  51. ;;
  52. ;; Elp can instrument byte-compiled functions just as easily as
  53. ;; interpreted functions, but it cannot instrument macros.  However,
  54. ;; when you redefine a function (e.g. with eval-defun), you'll need to
  55. ;; re-instrument it with M-x elp-instrument-function.  This will also
  56. ;; reset profiling information for that function.  Elp can handle
  57. ;; interactive functions (i.e. commands), but of course any time spent
  58. ;; idling for user prompts will show up in the timing results.
  59. ;;
  60. ;; You can also designate a `master' function.  Profiling times will
  61. ;; be gathered for instrumented functions only during execution of
  62. ;; this master function.  Thus, if you have some defuns like:
  63. ;;
  64. ;;  (defun foo () (do-something-time-intensive))
  65. ;;  (defun bar () (foo))
  66. ;;  (defun baz () (bar) (foo))
  67. ;;
  68. ;; and you want to find out the amount of time spent in bar and foo,
  69. ;; but only during execution of bar, make bar the master.  The call of
  70. ;; foo from baz will not add to foo's total timing sums.  Use M-x
  71. ;; elp-set-master and M-x elp-unset-master to utilize this feature.
  72. ;; Only one master function can be set at a time.
  73.  
  74. ;; You can restore any function's original function definition with
  75. ;; elp-restore-function.  The other instrument, restore, and reset
  76. ;; functions are provided for symmetry.
  77.  
  78. ;; Here is a list of variable you can use to customize elp:
  79. ;;   elp-function-list
  80. ;;   elp-reset-after-results
  81. ;;   elp-sort-by-function
  82. ;;   elp-report-limit
  83. ;;
  84. ;; Here is a list of the interactive commands you can use:
  85. ;;   elp-instrument-function
  86. ;;   elp-restore-function
  87. ;;   elp-instrument-list
  88. ;;   elp-restore-list
  89. ;;   elp-instrument-package
  90. ;;   elp-restore-all
  91. ;;   elp-reset-function
  92. ;;   elp-reset-list
  93. ;;   elp-reset-all
  94. ;;   elp-set-master
  95. ;;   elp-unset-master
  96. ;;   elp-results
  97. ;;   elp-submit-bug-report
  98.  
  99. ;; Note that there are plenty of factors that could make the times
  100. ;; reported unreliable, including the accuracy and granularity of your
  101. ;; system clock, and the overhead spent in lisp calculating and
  102. ;; recording the intervals.  I figure the latter is pretty constant,
  103. ;; so while the times may not be entirely accurate, I think they'll
  104. ;; give you a good feel for the relative amount of work spent in the
  105. ;; various lisp routines you are profiling.  Note further that times
  106. ;; are calculated using wall-clock time, so other system load will
  107. ;; affect accuracy too.  You cannot profile anything longer than ~18
  108. ;; hours since I throw away the most significant 16 bits of seconds
  109. ;; returned by current-time: 2^16 == 65536 seconds == ~1092 minutes ==
  110. ;; ~18 hours.  I doubt you will ever want to profile stuff on the
  111. ;; order of 18 hours anyway.
  112.  
  113. ;;; Background:
  114. ;;
  115. ;; This program was inspired by the only two existing Emacs Lisp
  116. ;; profilers that I'm aware of, Boaz Ben-Zvi's profile.el, and Root
  117. ;; Boy Jim's profiler.el. Both were written for Emacs 18 and both were
  118. ;; pretty good first shots at profiling, but I found that they didn't
  119. ;; provide the functionality or interface that I wanted, so I wrote
  120. ;; this.  I've tested elp in XEmacs 19 and Emacs 19.  There's no point
  121. ;; in even trying to make this work with Emacs 18.
  122.  
  123. ;; Unlike previous profilers, elp uses Emacs 19's built-in function
  124. ;; current-time to return interval times.  This obviates the need for
  125. ;; both an external C program and Emacs processes to communicate with
  126. ;; such a program, and thus simplifies the package as a whole.
  127.  
  128. ;; TBD:
  129. ;; Make this act like a real profiler, so that it records time spent
  130. ;; in all branches of execution.
  131.  
  132. ;;; Code:
  133.  
  134.  
  135. ;; start of user configuration variables
  136. ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  137.  
  138. (defgroup elp nil
  139.   "Emacs Lisp Profiler"
  140.   :group 'lisp)
  141.  
  142.  
  143. (defcustom elp-function-list nil
  144.   "*List of functions to profile.
  145. Used by the command `elp-instrument-list'."
  146.   :type '(repeat function)
  147.   :group 'elp)
  148.  
  149. (defcustom elp-reset-after-results t
  150.   "*Non-nil means reset all profiling info after results are displayed.
  151. Results are displayed with the `elp-results' command."
  152.   :type 'boolean
  153.   :group 'elp)
  154.  
  155. (defcustom elp-sort-by-function 'elp-sort-by-total-time
  156.   "*Non-nil specifies elp results sorting function.
  157. These functions are currently available:
  158.  
  159.   elp-sort-by-call-count   -- sort by the highest call count
  160.   elp-sort-by-total-time   -- sort by the highest total time
  161.   elp-sort-by-average-time -- sort by the highest average times
  162.  
  163. You can write you're own sort function. It should adhere to the
  164. interface specified by the PRED argument for the `sort' defun.  Each
  165. \"element of LIST\" is really a 4 element vector where element 0 is
  166. the call count, element 1 is the total time spent in the function,
  167. element 2 is the average time spent in the function, and element 3 is
  168. the symbol's name string."
  169.   :type 'function
  170.   :group 'elp)
  171.  
  172. (defcustom elp-report-limit 1
  173.   "*Prevents some functions from being displayed in the results buffer.
  174. If a number, no function that has been called fewer than that number
  175. of times will be displayed in the output buffer.  If nil, all
  176. functions will be displayed."
  177.   :type '(choice integer
  178.          (const :tag "All" nil))
  179.   :group 'elp)
  180.  
  181. (defcustom elp-use-standard-output nil
  182.   "*Non-nil says to output to `standard-output' instead of a buffer."
  183.   :type 'boolean
  184.   :group 'elp)
  185.  
  186. (defcustom elp-recycle-buffers-p t
  187.   "*Nil says to not recycle the `elp-results-buffer'.
  188. In other words, a new unique buffer is create every time you run
  189. \\[elp-results]."
  190.   :type 'boolean
  191.   :group 'elp)
  192.  
  193.  
  194. ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  195. ;; end of user configuration variables
  196.  
  197.  
  198. (defconst elp-version "2.37"
  199.   "ELP version number.")
  200.  
  201. (defconst elp-help-address "tools-help@python.org"
  202.   "Address accepting submissions of bug reports and questions.")
  203.  
  204. (defvar elp-results-buffer "*ELP Profiling Results*"
  205.   "Buffer name for outputting profiling results.")
  206.  
  207. (defconst elp-timer-info-property 'elp-info
  208.   "ELP information property name.")
  209.  
  210. (defvar elp-all-instrumented-list nil
  211.   "List of all functions currently being instrumented.")
  212.  
  213. (defvar elp-record-p t
  214.   "Controls whether functions should record times or not.
  215. This variable is set by the master function.")
  216.  
  217. (defvar elp-master nil
  218.   "Master function symbol.")
  219.  
  220.  
  221. ;;;###autoload
  222. (defun elp-instrument-function (funsym)
  223.   "Instrument FUNSYM for profiling.
  224. FUNSYM must be a symbol of a defined function."
  225.   (interactive "aFunction to instrument: ")
  226.   ;; restore the function.  this is necessary to avoid infinite
  227.   ;; recursion of already instrumented functions (i.e. elp-wrapper
  228.   ;; calling elp-wrapper ad infinitum).  it is better to simply
  229.   ;; restore the function than to throw an error.  this will work
  230.   ;; properly in the face of eval-defun because if the function was
  231.   ;; redefined, only the timer info will be nil'd out since
  232.   ;; elp-restore-function is smart enough not to trash the new
  233.   ;; definition.
  234.   (elp-restore-function funsym)
  235.   (let* ((funguts (symbol-function funsym))
  236.      (infovec (vector 0 0 funguts))
  237.      (newguts '(lambda (&rest args))))
  238.     ;; we cannot profile macros
  239.     (and (eq (car-safe funguts) 'macro)
  240.      (error "ELP cannot profile macro: %s" funsym))
  241.     ;; TBD: at some point it might be better to load the autoloaded
  242.     ;; function instead of throwing an error.  if we do this, then we
  243.     ;; probably want elp-instrument-package to be updated with the
  244.     ;; newly loaded list of functions.  i'm not sure it's smart to do
  245.     ;; the autoload here, since that could have side effects, and
  246.     ;; elp-instrument-function is similar (in my mind) to defun-ish
  247.     ;; type functionality (i.e. it shouldn't execute the function).
  248.     (and (eq (car-safe funguts) 'autoload)
  249.      (error "ELP cannot profile autoloaded function: %s" funsym))
  250.     ;; put rest of newguts together
  251.     (if (commandp funsym)
  252.     (setq newguts (append newguts '((interactive)))))
  253.     (setq newguts (append newguts (list
  254.                    (list 'elp-wrapper
  255.                      (list 'quote funsym)
  256.                      (list 'and
  257.                            '(interactive-p)
  258.                            (not (not (commandp funsym))))
  259.                      'args))))
  260.     ;; to record profiling times, we set the symbol's function
  261.     ;; definition so that it runs the elp-wrapper function with the
  262.     ;; function symbol as an argument.  We place the old function
  263.     ;; definition on the info vector.
  264.     ;;
  265.     ;; The info vector data structure is a 3 element vector.  The 0th
  266.     ;; element is the call-count, i.e. the total number of times this
  267.     ;; function has been entered.  This value is bumped up on entry to
  268.     ;; the function so that non-local exists are still recorded. TBD:
  269.     ;; I haven't tested non-local exits at all, so no guarantees.
  270.     ;;
  271.     ;; The 1st element is the total amount of time in usecs that have
  272.     ;; been spent inside this function.  This number is added to on
  273.     ;; function exit.
  274.     ;;
  275.     ;; The 2nd element is the old function definition list.  This gets
  276.     ;; funcall'd in between start/end time retrievals. I believe that
  277.     ;; this lets us profile even byte-compiled functions.
  278.  
  279.     ;; put the info vector on the property list
  280.     (put funsym elp-timer-info-property infovec)
  281.  
  282.     ;; set the symbol's new profiling function definition to run
  283.     ;; elp-wrapper
  284.     (fset funsym newguts)
  285.  
  286.     ;; add this function to the instrumentation list
  287.     (or (memq funsym elp-all-instrumented-list)
  288.     (setq elp-all-instrumented-list
  289.           (cons funsym elp-all-instrumented-list)))
  290.     ))
  291.  
  292. ;;;###autoload
  293. (defun elp-restore-function (funsym)
  294.   "Restore an instrumented function to its original definition.
  295. Argument FUNSYM is the symbol of a defined function."
  296.   (interactive "aFunction to restore: ")
  297.   (let ((info (get funsym elp-timer-info-property)))
  298.     ;; delete the function from the all instrumented list
  299.     (setq elp-all-instrumented-list
  300.       (delq funsym elp-all-instrumented-list))
  301.  
  302.     ;; if the function was the master, reset the master
  303.     (if (eq funsym elp-master)
  304.     (setq elp-master nil
  305.           elp-record-p t))
  306.  
  307.     ;; zap the properties
  308.     (put funsym elp-timer-info-property nil)
  309.  
  310.     ;; restore the original function definition, but if the function
  311.     ;; wasn't instrumented do nothing.  we do this after the above
  312.     ;; because its possible the function got un-instrumented due to
  313.     ;; circumstances beyond our control.  Also, check to make sure
  314.     ;; that the current function symbol points to elp-wrapper.  If
  315.     ;; not, then the user probably did an eval-defun, or loaded a
  316.     ;; byte-compiled version, while the function was instrumented and
  317.     ;; we don't want to destroy the new definition.  can it ever be
  318.     ;; the case that a lisp function can be compiled instrumented?
  319.     (and info
  320.      (not (compiled-function-p (symbol-function funsym)))
  321.      (assq 'elp-wrapper (symbol-function funsym))
  322.      (fset funsym (aref info 2)))))
  323.  
  324. ;;;###autoload
  325. (defun elp-instrument-list (&optional list)
  326.   "Instrument for profiling, all functions in `elp-function-list'.
  327. Use optional LIST if provided instead."
  328.   (interactive "PList of functions to instrument: ")
  329.   (let ((list (or list elp-function-list)))
  330.     (mapcar 'elp-instrument-function list)))
  331.  
  332. ;;;###autoload
  333. (defun elp-instrument-package (prefix)
  334.   "Instrument for profiling, all functions which start with PREFIX.
  335. For example, to instrument all ELP functions, do the following:
  336.  
  337.     \\[elp-instrument-package] RET elp- RET"
  338.   (interactive "sPrefix of package to instrument: ")
  339.   (elp-instrument-list
  340.    (mapcar 'intern (all-completions prefix obarray
  341.                     (function
  342.                      (lambda (sym)
  343.                        (and (fboundp sym)
  344.                         (not (eq (car-safe
  345.                               (symbol-function sym))
  346.                              'macro)))))))))
  347.  
  348. (defun elp-restore-list (&optional list)
  349.   "Restore the original definitions for all functions in `elp-function-list'.
  350. Use optional LIST if provided instead."
  351.   (interactive "PList of functions to restore: ")
  352.   (let ((list (or list elp-function-list)))
  353.     (mapcar 'elp-restore-function list)))
  354.  
  355. (defun elp-restore-all ()
  356.   "Restores the original definitions of all functions being profiled."
  357.   (interactive)
  358.   (elp-restore-list elp-all-instrumented-list))
  359.  
  360.  
  361. (defun elp-reset-function (funsym)
  362.   "Reset the profiling information for FUNSYM."
  363.   (interactive "aFunction to reset: ")
  364.   (let ((info (get funsym elp-timer-info-property)))
  365.     (or info
  366.     (error "%s is not instrumented for profiling." funsym))
  367.     (aset info 0 0)            ;reset call counter
  368.     (aset info 1 0.0)            ;reset total time
  369.     ;; don't muck with aref 2 as that is the old symbol definition
  370.     ))
  371.  
  372. (defun elp-reset-list (&optional list)
  373.   "Reset the profiling information for all functions in `elp-function-list'.
  374. Use optional LIST if provided instead."
  375.   (interactive "PList of functions to reset: ")
  376.   (let ((list (or list elp-function-list)))
  377.     (mapcar 'elp-reset-function list)))
  378.  
  379. (defun elp-reset-all ()
  380.   "Reset the profiling information for all functions being profiled."
  381.   (interactive)
  382.   (elp-reset-list elp-all-instrumented-list))
  383.  
  384. (defun elp-set-master (funsym)
  385.   "Set the master function for profiling."
  386.   (interactive "aMaster function: ")
  387.   ;; when there's a master function, recording is turned off by
  388.   ;; default
  389.   (setq elp-master funsym
  390.     elp-record-p nil)
  391.   ;; make sure master function is instrumented
  392.   (or (memq funsym elp-all-instrumented-list)
  393.       (elp-instrument-function funsym)))
  394.  
  395. (defun elp-unset-master ()
  396.   "Unsets the master function."
  397.   (interactive)
  398.   ;; when there's no master function, recording is turned on by default.
  399.   (setq elp-master nil
  400.     elp-record-p t))
  401.  
  402.  
  403. (defsubst elp-get-time ()
  404.   ;; get current time in seconds and microseconds. I throw away the
  405.   ;; most significant 16 bits of seconds since I doubt we'll ever want
  406.   ;; to profile lisp on the order of 18 hours. See notes at top of file.
  407.   (let ((now (current-time)))
  408.     (+ (float (nth 1 now)) (/ (float (nth 2 now)) 1000000.0))))
  409.  
  410. (defun elp-wrapper (funsym interactive-p args)
  411.   "This function has been instrumented for profiling by the ELP.
  412. ELP is the Emacs Lisp Profiler.  To restore the function to its
  413. original definition, use \\[elp-restore-function] or \\[elp-restore-all]."
  414.   ;; turn on recording if this is the master function
  415.   (if (and elp-master
  416.        (eq funsym elp-master))
  417.       (setq elp-record-p t))
  418.   ;; get info vector and original function symbol
  419.   (let* ((info (get funsym elp-timer-info-property))
  420.      (func (aref info 2))
  421.      result)
  422.     (or func
  423.     (error "%s is not instrumented for profiling." funsym))
  424.     (if (not elp-record-p)
  425.     ;; when not recording, just call the original function symbol
  426.     ;; and return the results.
  427.     (setq result
  428.           (if interactive-p
  429.           (call-interactively func)
  430.         (apply func args)))
  431.       ;; we are recording times
  432.       (let ((enter-time (elp-get-time)))
  433.     ;; increment the call-counter
  434.     (aset info 0 (1+ (aref info 0)))
  435.     ;; now call the old symbol function, checking to see if it
  436.     ;; should be called interactively.  make sure we return the
  437.     ;; correct value
  438.     (setq result
  439.           (if interactive-p
  440.           (call-interactively func)
  441.         (apply func args)))
  442.     ;; calculate total time in function
  443.     (aset info 1 (+ (aref info 1) (- (elp-get-time) enter-time)))
  444.     ))
  445.     ;; turn off recording if this is the master function
  446.     (if (and elp-master
  447.          (eq funsym elp-master))
  448.     (setq elp-record-p nil))
  449.     result))
  450.  
  451.  
  452. ;; shut the byte-compiler up
  453. (defvar elp-field-len nil)
  454. (defvar elp-cc-len nil)
  455. (defvar elp-at-len nil)
  456. (defvar elp-et-len nil)
  457.  
  458. (defun elp-sort-by-call-count (vec1 vec2)
  459.   ;; sort by highest call count.  See `sort'.
  460.   (>= (aref vec1 0) (aref vec2 0)))
  461.  
  462. (defun elp-sort-by-total-time (vec1 vec2)
  463.   ;; sort by highest total time spent in function. See `sort'.
  464.   (>= (aref vec1 1) (aref vec2 1)))
  465.  
  466. (defun elp-sort-by-average-time (vec1 vec2)
  467.   ;; sort by highest average time spent in function. See `sort'.
  468.   (>= (aref vec1 2) (aref vec2 2)))
  469.  
  470. (defsubst elp-pack-number (number width)
  471.   ;; pack the NUMBER string into WIDTH characters, watching out for
  472.   ;; very small or large numbers
  473.   (if (<= (length number) width)
  474.       number
  475.     ;; check for very large or small numbers
  476.     (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number)
  477.     (concat (substring
  478.          (substring number (match-beginning 1) (match-end 1))
  479.          0
  480.          (- width (match-end 2) (- (match-beginning 2)) 3))
  481.         "..."
  482.         (substring number (match-beginning 2) (match-end 2)))
  483.       (concat (substring number 0 width)))))
  484.  
  485. (defun elp-output-result (resultvec)
  486.   ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or
  487.   ;; more element vector where aref 0 is the call count, aref 1 is the
  488.   ;; total time spent in the function, aref 2 is the average time
  489.   ;; spent in the function, and aref 3 is the symbol's string
  490.   ;; name. All other elements in the vector are ignored.
  491.   (let* ((cc (aref resultvec 0))
  492.      (tt (aref resultvec 1))
  493.      (at (aref resultvec 2))
  494.      (symname (aref resultvec 3))
  495.      callcnt totaltime avetime)
  496.     (setq callcnt (number-to-string cc)
  497.       totaltime (number-to-string tt)
  498.       avetime (number-to-string at))
  499.     ;; possibly prune the results
  500.     (if (and elp-report-limit
  501.          (numberp elp-report-limit)
  502.          (< cc elp-report-limit))
  503.     nil
  504.       (insert symname)
  505.       (insert-char 32 (+ elp-field-len (- (length symname)) 2))
  506.       ;; print stuff out, formatting it nicely
  507.       (insert callcnt)
  508.       (insert-char 32 (+ elp-cc-len (- (length callcnt)) 2))
  509.       (let ((ttstr (elp-pack-number totaltime elp-et-len))
  510.         (atstr (elp-pack-number avetime elp-at-len)))
  511.     (insert ttstr)
  512.     (insert-char 32 (+ elp-et-len (- (length ttstr)) 2))
  513.     (insert atstr))
  514.       (insert "\n"))))
  515.  
  516. ;;;###autoload
  517. (defun elp-results ()
  518.   "Display current profiling results.
  519. If `elp-reset-after-results' is non-nil, then current profiling
  520. information for all instrumented functions are reset after results are
  521. displayed."
  522.   (interactive)
  523.   (let ((curbuf (current-buffer))
  524.     (resultsbuf (if elp-recycle-buffers-p
  525.             (get-buffer-create elp-results-buffer)
  526.               (generate-new-buffer elp-results-buffer))))
  527.     (set-buffer resultsbuf)
  528.     (erase-buffer)
  529.     (beginning-of-buffer)
  530.     ;; get the length of the longest function name being profiled
  531.     (let* ((longest 0)
  532.        (title "Function Name")
  533.        (titlelen (length title))
  534.        (elp-field-len titlelen)
  535.        (cc-header "Call Count")
  536.        (elp-cc-len    (length cc-header))
  537.        (et-header "Elapsed Time")
  538.        (elp-et-len    (length et-header))
  539.        (at-header "Average Time")
  540.        (elp-at-len    (length at-header))
  541.        (resvec
  542.         (mapcar
  543.          (function
  544.           (lambda (funsym)
  545.         (let* ((info (get funsym elp-timer-info-property))
  546.                (symname (format "%s" funsym))
  547.                (cc (aref info 0))
  548.                (tt (aref info 1)))
  549.           (if (not info)
  550.               (insert "No profiling information found for: "
  551.                   symname)
  552.             (setq longest (max longest (length symname)))
  553.             (vector cc tt (if (zerop cc)
  554.                       0.0 ;avoid arithmetic div-by-zero errors
  555.                     (/ (float tt) (float cc)))
  556.                 symname)))))
  557.          elp-all-instrumented-list))
  558.        )                ; end let*
  559.       (insert title)
  560.       (if (> longest titlelen)
  561.       (progn
  562.         (insert-char 32 (- longest titlelen))
  563.         (setq elp-field-len longest)))
  564.       (insert "  " cc-header "  " et-header "  " at-header "\n")
  565.       (insert-char ?= elp-field-len)
  566.       (insert "  ")
  567.       (insert-char ?= elp-cc-len)
  568.       (insert "  ")
  569.       (insert-char ?= elp-et-len)
  570.       (insert "  ")
  571.       (insert-char ?= elp-at-len)
  572.       (insert "\n")
  573.       ;; if sorting is enabled, then sort the results list. in either
  574.       ;; case, call elp-output-result to output the result in the
  575.       ;; buffer
  576.       (if elp-sort-by-function
  577.       (setq resvec (sort resvec elp-sort-by-function)))
  578.       (mapcar 'elp-output-result resvec))
  579.     ;; now pop up results buffer
  580.     (set-buffer curbuf)
  581.     (pop-to-buffer resultsbuf)
  582.     ;; copy results to standard-output?
  583.     (if (or elp-use-standard-output noninteractive)
  584.     (princ (buffer-substring (point-min) (point-max))))
  585.     ;; reset profiling info if desired
  586.     (and elp-reset-after-results
  587.      (elp-reset-all))))
  588.  
  589.  
  590. (eval-when-compile
  591.  (require 'reporter))
  592.  
  593. ;;;###autoload
  594. (defun elp-submit-bug-report ()
  595.   "Submit via mail, a bug report on elp."
  596.   (interactive)
  597.   (and
  598.    (y-or-n-p "Do you want to submit a report on elp? ")
  599.    (require 'reporter)
  600.    (reporter-submit-bug-report
  601.     elp-help-address (concat "elp " elp-version)
  602.     '(elp-report-limit
  603.       elp-reset-after-results
  604.       elp-sort-by-function))))
  605.  
  606.  
  607. (provide 'elp)
  608. ;; elp.el ends here
  609.